/***************************************/
/*  Use MADS http://mads.atari8.info/  */
/*  Mode: DLI (char mode)              */
/***************************************/

hposp0	= $D000
hposp1	= $D001
hposp2	= $D002
hposp3	= $D003
hposm0	= $D004
hposm1	= $D005
hposm2	= $D006
hposm3	= $D007
sizep0	= $D008
sizep1	= $D009
sizep2	= $D00A
sizep3	= $D00B
sizem	= $D00C
colpm0	= $D012
colpm1	= $D013
colpm2	= $D014
colpm3	= $D015
color0	= $D016
color1	= $D017
color2	= $D018
color3	= $D019
colbak	= $D01A
gtictl	= $D01B
pmcntl	= $D01D
hitclr	= $D01E
skctl	= $D20F
portb	= $D301
dmactl	= $D400
dlptr	= $D402
vscrol	= $D405
pmbase	= $D407
chbase	= $D409
wsync	= $D40A
vcount	= $D40B
nmien	= $D40E
nmist	= $D40F


	org $00

fcnt	.ds 2
fadr	.ds 2
cloc	.ds 1
regA	.ds 1
regX	.ds 1
regY	.ds 1


* ---	BASIC switch OFF
	org $2000\ mva #$ff portb\ rts\ ini $2000

* ---	MAIN PROGRAM
	org $1400
ant	dta $42,a(scr)
	dta $02,$82,$02,$02,$82,$02,$02,$82,$02,$02,$82,$02,$02,$82,$02,$02
	dta $82,$02,$02,$82,$02,$02,$82,$02,$02,$82,$02,$02,$22
	dta $41,a(ant)

scr	ins 'slide.scr'

	.ALIGN $0400
fnt	ins 'obr1.fnt'
	.ALIGN $0400
fnt1	ins 'obr2.fnt'
	.ALIGN $0400
fnt2	ins 'obr3.fnt'
	.ALIGN $0400
fnt3	ins 'obr4.fnt'

	.ifdef USESPRITES
	.ALIGN $0800
	.ds $0300
pmg	SPRITES
	eif

main
 lda >fnt
 sta $91
 lda >fnt+$400*$01
 sta $92
 lda >fnt+$400*$02
 sta $93
 lda >fnt+$400*$03
 sta $94
 lda >fnt+$400*$04
 sta $95
 lda >fnt+$400*$05
 sta $96
 lda >fnt+$400*$06
 sta $97
 lda >fnt+$400*$07
 sta $98
 lda >fnt+$400*$08
 sta $99
 lda >fnt+$400*$09
 lda >fnt+$400*$09
 sta $9a
 lda #$10
 sta $9b

* ---	init PMG

	.ifdef USESPRITES
	mva >pmg pmbase		;missiles and players data address
	mva #$03 pmcntl		;enable players and missiles
	eif

	lda:cmp:req $14		;wait 1 frame

	sei			;stop IRQ interrupts
	mva #$00 nmien		;stop NMI interrupts
	mva #$fe portb		;switch off ROM to get 16k more ram

	mwa #NMI $fffa		;new NMI handler

	mva #1 vscrol

	mva #$c0 nmien		;switch on NMI+DLI again

	.ifdef CHANGES		;if label CHANGES defined

_lp	lda skctl		;wait to press any key; here you can put any own routine
	and #$04
	bne _lp

	mva #$00 pmcntl		;PMG disabled
	tax
	sta:rne hposp0,x+

	mva #$ff portb		;ROM switch on
	mva #$40 nmien		;only NMI interrupts, DLI disabled
	cli			;IRQ enabled
	jmp ($000a)		;jump to DOS

	els

null	jmp dli1		;CPU is busy here, so no more routines allowed

	eif


* ---	DLI PROGRAM

	?old_dli = *

dli1
	lda vcount
	cmp #$02
	bne dli1
	:3 sta wsync
	DLINEW dli2 1 0 0
dli_start


dli2
	lda $92
	sta wsync		;line=24
	sta chbase
	DLINEW dli3 1 0 0

dli3
	lda $93
	sta wsync		;line=48
	sta chbase
	DLINEW dli4 1 0 0

dli4
	lda $94
	sta wsync		;line=72
	sta chbase
	DLINEW dli5 1 0 0

dli5
	lda $95
	sta wsync		;line=96
	sta chbase
	DLINEW dli6 1 0 0

dli6
	lda $96
	sta wsync		;line=120
	sta chbase
	DLINEW dli7 1 0 0

dli7
	lda $97
	sta wsync		;line=144
	sta chbase
	DLINEW dli8 1 0 0

dli8
	lda $98
	sta wsync		;line=168
	sta chbase
	DLINEW dli9 1 0 0

dli9
	lda $99
	sta wsync		;line=192
	sta chbase
	DLINEW dli10 1 0 0

dli10
	lda $9a
	sta wsync		;line=216
	sta chbase

	lda regA
	rti

;---

CHANGES

;---

.proc	NMI

	sta regA
	stx regX
	sty regY

	bit nmist
	bpl VBL

	jmp dli_start
dliv	equ *-2

VBL
	sta nmist		;reset NMI flag

	mwa #ant dlptr		;ANTIC address program

	mva #%00111110 dmactl	;set new screen's width

	inc cloc		;little timer

;--- first line of screen initialization

	lda $91
	sta chbase
c0	lda $9b
	sta colbak
c1	lda #$04
	sta color0
c2	lda #$06
	sta color1
c3	lda #$08
	sta color2
c4	lda #$0E
	sta color3
	lda #$44
	sta gtictl

	mwa #dli_start dliv	;set the first address of DLI interrupt

;this area is for yours routines
 jsr proc
quit
	lda regA
	ldx regX
	ldy regY
	rti

.endp

;---
	run main
;---

 org $bf00
switch .byte 0
timer .byte 1
proc
 ldx timer
 dex
 txa
 sta timer
 beq nextobr
 rts
nextobr
 lda #255
 sta timer

 lda switch
 cmp #0 
 beq obr1
 cmp #1
 beq obr2
 cmp #2
 beq obr3
 jmp obr4

obr1
 lda #$10
 sta $9b
 lda >fnt
 sta $91
 lda >fnt+$400*$01
 sta $92
 lda >fnt+$400*$02
 sta $93
 lda >fnt+$400*$03
 sta $94
 lda >fnt+$400*$04
 sta $95
 lda >fnt+$400*$05
 sta $96
 lda >fnt+$400*$06
 sta $97
 lda >fnt+$400*$07
 sta $98
 lda >fnt+$400*$08
 sta $99
 lda >fnt+$400*$09
 sta $9a
 lda #$1
 sta switch
 rts

obr2
 lda #$b0
 sta $9b
 lda >fnt1
 sta $91
 lda >fnt1+$400*$01
 sta $92
 lda >fnt1+$400*$02
 sta $93
 lda >fnt1+$400*$03
 sta $94
 lda >fnt1+$400*$04
 sta $95
 lda >fnt1+$400*$05
 sta $96
 lda >fnt1+$400*$06
 sta $97
 lda >fnt1+$400*$07
 sta $98
 lda >fnt1+$400*$08
 sta $99
 lda >fnt1+$400*$09
 sta $9a
 lda #2
 sta switch
 rts

obr3
 lda #$50
 sta $9b
 lda >fnt2
 sta $91
 lda >fnt2+$400*$01
 sta $92
 lda >fnt2+$400*$02
 sta $93
 lda >fnt2+$400*$03
 sta $94
 lda >fnt2+$400*$04
 sta $95
 lda >fnt2+$400*$05
 sta $96
 lda >fnt2+$400*$06
 sta $97
 lda >fnt2+$400*$07
 sta $98
 lda >fnt2+$400*$08
 sta $99
 lda >fnt2+$400*$09
 sta $9a
 lda #3
 sta switch
 rts

obr4
 lda #$00
 sta $9b
 lda >fnt3
 sta $91
 lda >fnt3+$400*$01
 sta $92
 lda >fnt3+$400*$02
 sta $93
 lda >fnt3+$400*$03
 sta $94
 lda >fnt3+$400*$04
 sta $95
 lda >fnt3+$400*$05
 sta $96
 lda >fnt3+$400*$06
 sta $97
 lda >fnt3+$400*$07
 sta $98
 lda >fnt3+$400*$08
 sta $99
 lda >fnt3+$400*$09
 sta $9a
 lda #0
 sta switch
 rts

	opt l-

.MACRO	SPRITES
	.ds $100
	.ds $100
	.ds $100
	.ds $100
	.ds $100
.ENDM

.MACRO	DLINEW
	mva <:1 NMI.dliv
	ift [>?old_dli]<>[>:1]
	mva >:1 NMI.dliv+1
	eif

	ift :2
	lda regA
	eif

	ift :3
	ldx regX
	eif

	ift :4
	ldy regY
	eif

	rti

	.def ?old_dli = *
.ENDM

